<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\BroadcastMessage;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class SiteNotice extends Notification implements ShouldQueue
{
    use Queueable;

    public $notice;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($notice)
    {
        //
        $this->notice=$notice;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['database'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->from('1365271761@qq.com','江西菜东家农业发展有限公司')
            ->subject('通知消息')
            ->greeting('您好!')
            ->line($this->notice->content)
//            ->action('查看通知', url('/'))
            ->line('感谢您对菜东家的支持!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return $this->notice->id;
    }

    public function toBroadcast($notifiable)
    {
        return new BroadcastMessage([
            'id' => $this->notice->id,
            'title' => $this->notice->title,
            'content' => $this->notice->content,
            'created_at' => $this->notice->created_at,
        ]);
    }

}
